import { Controller, Get, Param, Post, UseGuards, Body, ParseIntPipe } from "@nestjs/common";
import { UserService } from "./user.service";
import { User } from "../../SharModule/entities/user.entity";
import { UserDto, editUserDto } from "./user.dto";
import { AuthGuard } from "@nestjs/passport";

@Controller('user')
export class UserController{
    constructor(private readonly UserService:UserService){}

    @Get()
    @UseGuards(AuthGuard())
    async findAll():Promise<User[]> {
        return await this.UserService.findAll();
    }

    @Get(':id')
    async findOne(@Param('id',new ParseIntPipe()) id:number):Promise<User> {
        return await this.UserService.findOne({id});
    }

    @Post('create')
    @UseGuards(AuthGuard())
    async create(@Body() user:UserDto):Promise<User>{
        return await this.UserService.create(user);
    }

    @Post('edit')
    @UseGuards(AuthGuard())
    async edit(@Body() user:editUserDto):Promise<User>{
        return await this.UserService.edit(user);
    }

    @Get('remove/:id')
    async remove(@Param('id',new ParseIntPipe()) id:number):Promise<User> {
        return await this.UserService.remove({id});
    }
}